import { PureComponent } from 'react';
import moment from 'moment';
import '@/assets/iconfont/iconfont';
import styles from './StaffInfoList.less';
import SelectDeptTree from '@/components/SelectDeptTree';
import { dicTextByCodePcode,dicListByPcode } from '@/utils/dictionary'
import {
    Row,
    Col,
    Form,
    Input,
    Select,
    Modal,
    DatePicker,
    Button,
    Upload,
    Cascader
} from 'antd';
const FormItem = Form.Item;
const { Option } = Select;
const formItemLayout = {
 	labelCol: { span: 10 },
   	wrapperCol: { span: 14 },
};

@Form.create()
class UpdateForm extends PureComponent {

	constructor(props) {
		super(props);
		// const staffAge = moment().format('YYYY') - moment(props.values.date_of_birth).format('YYYY');
    this.state = {
			formVals: {
        za0100: props.values.za0100,
        id: props.values.id,
        a3301: props.values.a3301,
        a3304: props.values.a3304,
        a3307: props.values.a3307,
        a3311: props.values.a3311,
        a3314: props.values.a3314,
        a3317: props.values.a3317,
        a3321: props.values.a3321,
        a3324: props.values.a3324,
        a3327: props.values.a3327,
        a3331: props.values.a3331,
        a3334: props.values.a3334,
        a3337: props.values.a3337,
        a3341: props.values.a3341,
        a3344: props.values.a3344,
        a3345: props.values.a3345,
        a3346: props.values.a3346,
        a3347: props.values.a3347,
        a3312: props.values.a3312

			},
			getDeptTreeBySelectTree: "",
		};

	}


	componentWillReceiveProps(nextProps) {
		// if(undefined != nextProps.values && nextProps.values !== this.props.values) {
		// 	const staffAge = moment().format('YYYY') - moment(nextProps.values.date_of_birth).format('YYYY');
		//     this.setState({
		//       formVals: nextProps.values,
		//       imageUrl: nextProps.values.photo_sign,
		//       photoNum: nextProps.values.photo_sign?1:0,
		//       ageNum: staffAge?staffAge:null
		//     });
		// }

	}

	selectedDeptTreeValue = (deptRecord) => {
		this.setState({
			getDeptTreeBySelectTree: deptRecord
		})
	}



 	birthChange = value => {
		this.setState({
			ageNum: moment().format('YYYY') - value.format('YYYY')

		})
	}

	handleLocalUpdate = (event) => {
		event.preventDefault();
		const { form,handleSubmitSubsetInfo } = this.props;
		const { formVals: oldValue,getDeptTreeBySelectTree } = this.state;
		form.validateFields((err, fieldsValue) => {
			if(err) return;
			form.resetFields();
			const formVals = {
				...oldValue,
				...fieldsValue
			};
			this.setState({
				formVals,
			});

			/* if(getDeptTreeBySelectTree) {
				formVals.dept_id = getDeptTreeBySelectTree.triggerNode.props.dataRef.dept_id;
				formVals.dept = getDeptTreeBySelectTree.triggerNode.props.dataRef.title;
			}

			if(formVals.post) {
				formVals.post_id = formVals.post.key;
				formVals.post_name = formVals.post.label;
			}*/

			if(formVals.a3307) {
      			formVals.a3307 = moment(formVals.a3307._d).format("YYYY-MM-DD");
      		}
			// formVals.file = this.state.file; 
			handleSubmitSubsetInfo(formVals,"update_for_staff_familyMemberInfo");

		});
	};

  render() {
    const {
    	form: {getFieldDecorator},
    	falg,
      spinIndex,
    	cancelEditJobInfo,
    	cascaderList,
    	values,
    	selectDeptTree,
    	postForUser,
      requestModelName,
      dispatch
    } = this.props;

    const parentDeptTreeMethod = {
		dispatch: dispatch,
		selectDeptTree: selectDeptTree,
		selectedDeptTreeValue: this.selectedDeptTreeValue,
		requestModelName: requestModelName,
	}

    const { formVals,imageUrl,photoNum } = this.state;
    // 多选处理 TODO
    let newPlace = [];
    if(values.place_of_origin && values.place_of_origin != "null" ) {
    	const place = JSON.parse(values.place_of_origin);
    	newPlace = place.map((item,index) => item = item + '');
    }
	return (
		<div>
			{falg?(
				<Form  onSubmit={this.handleLocalUpdate}>

			    <Row gutter={{ md: 8, lg: 24, xl: 48 }}>

			        <Col md={12} sm={24}>
			          <FormItem  label="姓名">
			              {getFieldDecorator('a3301', {
			              rules: [{ required: true, message: '请输入1-10个字符',max: 10}],
			              initialValue: formVals.a3301,
			              })(<Input placeholder="1-10个字符"/>)}
			          </FormItem>
			        </Col>

              <Col md={12} sm={24}>
                <FormItem  label="与该人关系">
                    {getFieldDecorator('a3304', {
                      rules: [{ required: true, message: '请选择'}],
                      initialValue: formVals.a3304,
                    })(
                      <Select labelInValue placeholder="请选择" style={{ width: '100%' }}>
                      	{dicListByPcode('AE') != undefined?dicListByPcode('AE').map((item,index) => {
                      		return <Option value={item.DICTVALUE}>{item.DESCRIPTION}</Option>
                      	}):null}
                      </Select>
                    )}
                </FormItem>
              </Col>

			    </Row>
			    <Row gutter={{ md: 8, lg: 24, xl: 48 }}>

			        <Col md={12} sm={24}>
			          <FormItem  label="性别">
			              {getFieldDecorator('a3345',{
			              	initialValue: formVals.a3345,
			              })(
			              	<Select labelInValue placeholder="请选择" style={{ width: '100%' }}>
			              		{dicListByPcode('AE') != undefined?dicListByPcode('AE').map((item,index) => {
			              			return <Option value={item.DICTVALUE}>{item.DESCRIPTION}</Option>
			              		}):null}
			              	</Select>
			              )}
			          </FormItem>
			        </Col>
			        <Col md={12} sm={24}>
			          <FormItem  label="出生日期">
			              {getFieldDecorator('a3307', {
			              rules: [{ required: false, message: '请选择'}],
			              initialValue: formVals.a3307?moment(formVals.a3307):null,
			              })(<DatePicker  format="YYYY-MM-DD" style={{ width: '100%' }} placeholder="请选择"/>)}
			          </FormItem>
			        </Col>

			    </Row>

			    <Row gutter={{ md: 8, lg: 24, xl: 48 }}>

					<Col md={12} sm={24}>
			          <FormItem  label="政治面貌">
			              {getFieldDecorator('a3327', {
			              rules: [{ required: false, message: '请选择'}],
			              initialValue: formVals.a3327,
			              })(
			              	<Select labelInValue placeholder="请选择" style={{ width: '100%' }}>
			              	  	{dicListByPcode('YT') != undefined?dicListByPcode('YT').map((item,index) => {
			              	  		return <Option value={item.DICTVALUE}>{item.DESCRIPTION}</Option>
			              	  	}):null}
			              	  </Select>
			              )}
			          </FormItem>
			        </Col>

			        <Col md={12} sm={24}>
			          <FormItem  label="现状">
			              {getFieldDecorator('a3341',{
			                rules: [{ required: false, message: '请选择！'}],
                      initialValue: formVals.a3341,
			              })(
			              	<Select labelInValue placeholder="请选择" style={{ width: '100%' }}>
                        {dicListByPcode('R1') != undefined?dicListByPcode('R1').map((item,index) => {
                          return <Option value={item.DICTVALUE}>{item.DESCRIPTION}</Option>
                        }):null}
                      </Select>
			              )}
			          </FormItem>
			        </Col>

			    </Row>

			    <Row gutter={{ md: 8, lg: 24, xl: 48 }}>


			        <Col md={12} sm={24}>
			          <FormItem  label="工作单位名称">
			              {getFieldDecorator('a3311', {
			              rules: [{ required: false, message: '1-40个字符'}],
			              initialValue: formVals.a3311,
			              })(
                      <Input placeholder="1-40个字符" />
                    )}
			          </FormItem>
			        </Col>
			        <Col md={12} sm={24}>
			          <FormItem  label="工作单位所在政区">
			              {getFieldDecorator('a3314', {
                    rules: [{ required: false, message: '1-40个字符'}],
			              initialValue: formVals.a3314,
			              })(<Cascader options={cascaderList != undefined?cascaderList.list:null} onChange={this.onChange} placeholder="请选择" changeOnSelect />)}
			           </FormItem>
			        </Col>

			    </Row>

			    <Row gutter={{ md: 8, lg: 24, xl: 48 }}>


			        <Col md={12} sm={24}>
			          <FormItem  label="国籍">
			              {getFieldDecorator('a3317', {
			              rules: [{ required: false, message: '请选择' }],
			              initialValue: formVals.a3317,
                    })(<Cascader options={cascaderList != undefined?cascaderList.list:null} onChange={this.onChange} placeholder="请选择" changeOnSelect />)}
                    </FormItem>
			        </Col>

			       	<Col  md={12} sm={24}>
			       	  <FormItem  label="民族">
			       	      {getFieldDecorator('a3321', {
			       	        rules: [{ required: false, message: '请选择'}],
                      initialValue: formVals.a3321,
			       	        })(<Cascader options={cascaderList != undefined?cascaderList.list:null} onChange={this.onChange} placeholder="请选择" changeOnSelect />)}
			       	  </FormItem>
			       	</Col>

			    </Row>
			    <Row gutter={{ md: 8, lg: 24, xl: 48 }}>

			    	<Col md={12} sm={24}>
			    	  <FormItem  label="学历">
			    	      {getFieldDecorator('a3324', {
			    	        rules: [{ required: false, message: '请选择'}],
                    initialValue: formVals.a3324,
			    	        })(
			    	        <Select labelInValue placeholder="请选择" style={{ width: '100%' }}>
			    	        	{dicListByPcode('BG') != undefined?dicListByPcode('BG').map((item,index) => {
			    	        		return <Option value={item.DICTVALUE}>{item.DESCRIPTION}</Option>
			    	        	}):null}
			    	        </Select>
			    	      )}
			    	  </FormItem>
			    	</Col>

            <Col md={12} sm={24}>
              <FormItem  label="身份">
                  {getFieldDecorator('a3331', {
                    rules: [{ required: false, message: '请选择'}],
                    initialValue: formVals.a3331,
                    })(
                    <Select labelInValue placeholder="请选择" style={{ width: '100%' }}>
                    	{dicListByPcode('JK') != undefined?dicListByPcode('JK').map((item,index) => {
                    		return <Option value={item.DICTVALUE}>{item.DESCRIPTION}</Option>
                    	}):null}
                    </Select>
                  )}
              </FormItem>
            </Col>
			    </Row>

          <Row gutter={{ md: 8, lg: 24, xl: 48 }}>

          	<Col md={12} sm={24}>
          	  <FormItem  label="工作职务">
          	      {getFieldDecorator('a3312', {
          	        rules: [{ required: false, message: '1-40个字符'}],
                    initialValue: formVals.a3312,
          	        })(
          	        <Input placeholder="1-40个字符" />
          	      )}
          	  </FormItem>
          	</Col>

            <Col md={12} sm={24}>
              <FormItem  label="职务层次">
                  {getFieldDecorator('a3337', {
                    rules: [{ required: false, message: '1-40个字符'}],
                    initialValue: formVals.a3337,
                    })(
                    <Input placeholder="1-40个字符" />
                  )}
              </FormItem>
            </Col>
          </Row>

          <Row gutter={{ md: 8, lg: 24, xl: 48 }}>

          	<Col md={12} sm={24}>
          	  <FormItem  label="联系方式">
          	      {getFieldDecorator('a3347', {
          	        rules: [{ required: false, message: '1-40个字符'}],
                    initialValue: formVals.a3347,
          	        })(
          	        <Input placeholder="1-40个字符" />
          	      )}
          	  </FormItem>
          	</Col>

            <Col md={12} sm={24}>
              <FormItem  label="住址">
                  {getFieldDecorator('a3346', {
                    rules: [{ required: false, message: '1-40个字符'}],
                    initialValue: formVals.a3346,
                    })(
                    <Input placeholder="1-40个字符" />
                  )}
              </FormItem>
            </Col>
          </Row>

          <Row gutter={{ md: 8, lg: 24, xl: 48 }}>

          	<Col md={12} sm={24}>
          	  <FormItem  label="备注">
          	      {getFieldDecorator('a3344', {
          	        rules: [{ required: false, message: '1-40个字符'}],
                    initialValue: formVals.a3344,
          	        })(
          	        <Input placeholder="1-40个字符" />
          	      )}
          	  </FormItem>
          	</Col>

          </Row>

          <Row gutter={{ md: 8, lg: 24, xl: 48 }}>
          	<Col md={12} sm={24}>
                  <Button
                  	size="large"
                  	style={{marginRight: '10px'}}
                  	onClick={()=> {
                  		const { form } = this.props;
          				form.resetFields();
                  		cancelEditJobInfo(spinIndex);
                  	}}>
                  	取消
                 	</Button>
                  <Button size="large" type="primary" htmlType="submit">保存</Button>
              </Col>
          </Row>

			  </Form>
			):(
			<Form  {...formItemLayout}>

			    <Row gutter={{ md: 8, lg: 24, xl: 48 }}>

			        <Col md={12} sm={24}>
			          <FormItem  label="姓名">
			              {getFieldDecorator('a3301')(<span>{formVals.a3301}</span>)}
			          </FormItem>
			        </Col>

					<Col md={12} sm={24}>
			          <FormItem  label="与该人关系">
			              {getFieldDecorator('a3304')(<span>{formVals.a3304}</span>)}
			          </FormItem>
			        </Col>

			    </Row>
			    <Row gutter={{ md: 8, lg: 24, xl: 48 }}>

			        <Col md={12} sm={24}>
			          <FormItem  label="性别">
			              {getFieldDecorator('a3345')(<span>
			              	{(() => {
			              		return dicTextByCodePcode(formVals.a3345, 'AX');
				              	}
			             )()}
			            </span>)}
			          </FormItem>
			        </Col>
			        <Col md={12} sm={24}>
			          <FormItem  label="出生日期">
			              {getFieldDecorator('a3307')(<span>{formVals.a3307?moment(formVals.a3307).format('YYYY-MM-DD'):null}</span>)}
			          </FormItem>
			        </Col>

			    </Row>

			    <Row gutter={{ md: 8, lg: 24, xl: 48 }}>

					<Col md={12} sm={24}>
			          <FormItem  label="政治面貌">
			              {getFieldDecorator('a3327')(<span>{formVals.a3327}</span>)}
			          </FormItem>
			        </Col>
			        <Col md={12} sm={24}>
			          <FormItem  label="现状">
			              {getFieldDecorator('a3341')(<span>{formVals.a3341}
			              	</span>)}
			          </FormItem>
			        </Col>


			    </Row>

			    <Row gutter={{ md: 8, lg: 24, xl: 48 }}>

			        <Col md={12} sm={24}>
			          <FormItem  label="工作单位名称">
			              {getFieldDecorator('a3311')(<span>{formVals.a3311}</span>)}
			          </FormItem>
			        </Col>
			        <Col md={12} sm={24}>
			          <FormItem  label="工作单位所在政区">
			              {getFieldDecorator('a3314')(<span>{formVals.a3314}</span>)}
			          </FormItem>
			        </Col>

			    </Row>

			    <Row gutter={{ md: 8, lg: 24, xl: 48 }}>

			        <Col md={12} sm={24}>
			          <FormItem  label="国籍">
			              {getFieldDecorator('a3317')(<span>{formVals.a3317}</span>)}
			          </FormItem>
			        </Col>
			        <Col md={12} sm={24}>
			          <FormItem  label="民族">
			              {getFieldDecorator('a3321')(<span>{formVals.a3321}</span>)}
			          </FormItem>
			        </Col>

			    </Row>
			    <Row gutter={{ md: 8, lg: 24, xl: 48 }}>

			    	<Col  md={12} sm={24}>
				        <FormItem  label="学历">
				            {getFieldDecorator('a3324')(<span>{formVals.a3324}</span>)}
				        </FormItem>
			        </Col>
			        <Col md={12} sm={24}>
			          <FormItem  label="身份">
			              {getFieldDecorator('a3331')(<span>{formVals.a3331}
			              </span>)}
			          </FormItem>
			        </Col>

			    </Row>
          
          <Row gutter={{ md: 8, lg: 24, xl: 48 }}>
          
          	<Col  md={12} sm={24}>
                <FormItem  label="工作职务">
                    {getFieldDecorator('a3312')(<span>{formVals.a3312}</span>)}
                </FormItem>
              </Col>
              <Col md={12} sm={24}>
                <FormItem  label="职务层次">
                    {getFieldDecorator('a3337')(<span>{formVals.a3337}
                    </span>)}
                </FormItem>
              </Col>
          
          </Row>
          
          <Row gutter={{ md: 8, lg: 24, xl: 48 }}>
          
          	<Col  md={12} sm={24}>
                <FormItem  label="联系方式">
                    {getFieldDecorator('a3347')(<span>{formVals.a3347}</span>)}
                </FormItem>
              </Col>
              <Col md={12} sm={24}>
                <FormItem  label="住址">
                    {getFieldDecorator('a3346')(<span>{formVals.a3346}
                    </span>)}
                </FormItem>
              </Col>
          
          </Row>
          
          <Row gutter={{ md: 8, lg: 24, xl: 48 }}>
          
          	<Col  md={12} sm={24}>
                <FormItem  label="备注">
                    {getFieldDecorator('a3344')(<span>{formVals.a3344}</span>)}
                </FormItem>
              </Col>
          
          </Row>

			  </Form>
			)}
		</div>


	);
  }

}

export default UpdateForm;
